package org.insia.smartposse.idao;

import java.io.Serializable;
import java.util.List;

/**
 * Generic interface for DAO.
 *
 * @author sok hout
 * @version 1.02
 * @param <T> Class type.
 * @param <PK> Primary key type.
 */
public interface IGenericDAO<T, PK extends Serializable> {

    /**
     * Get the objec of type T by its id.
     *
     * @param id the id.
     * @return the object if it exist in database, or null.
     * @throws Exception
     */
    T get(PK id) throws Exception;

    /**
     * Create an instance of object of type T in hibernate and database.
     *
     * @param instance the instance of object to create.
     * @return the primary key of the created object.
     * @throws Exception
     */
    PK create(T instance) throws Exception;

    /**
     * Update the object in hibernate.
     *
     * @param transientObject the existing object in hibernate to update.
     * @throws Exception
     */
    void update(T transientObject) throws Exception;

    /**
     * Delete an object existing in hibernate.
     *
     * @param persistentObject the existing object to delete.
     * @throws Exception
     */
    void delete(T persistentObject) throws Exception;

    /**
     * Return the complete list of object T existing in hibernate.
     *
     * @return the complete list of object T.
     * @throws Exception
     */
    List<T> getList() throws Exception;

    /**
     * Return the list starting from a position.
     *
     * @start The start position.
     * @return The list of object starting from the start position.
     * @throws Exception
     */
    List<T> getList(int start) throws Exception;

    /**
     * Return the list of object between a start and end position.
     *
     * @param start the start position.
     * @param end the end position.
     * @return Liste the list between the start and end position.
     * @throws Exception
     */
    List<T> getList(int start, int end) throws Exception;

    /**
     * List the object by pages.
     *
     * @param nbPerPage Number of object by page.
     * @param numPage The page number.
     * @return the list of object of the page if they exist, or an empty list.
     * @throws Exception
     */
    List<T> getListPerPage(int nbPerPage, int numPage) throws Exception;

    /**
     * Return the number of existing object in hibernate.
     *
     * @return the number of object.
     * @throws Exception
     */
    long count() throws Exception;

    /**
     * Copy an object and save it in hibernate.
     *
     * @param persistantObject the object to copy.
     * @return The created object.
     * @throws Exception
     */
    PK copy(T persistantObject) throws Exception;
}
